package com.shfl.task.common;

import com.fasterxml.jackson.annotation.JsonInclude;

import java.util.List;

@JsonInclude(JsonInclude.Include.ALWAYS)
public class ApiResultPagingHelper<T, D> extends ApiResultHelper {

    private static final long serialVersionUID = -322702665364049413L;

    /**
     * 记录列表
     */
    List<T> content;

    /**
     * 记录总数
     */
    Long total;

    /**
     * 分页参数
     */
    Long pageSize;

    /**
     * 当前页数
     */
    Long page;

    Long pageCount;

    /**
     * 增加数据
     */
    private D data;


    /**
     * @param varl
     * @param total    记录总数
     * @param pageSize 分页参数
     * @param page     当前页数
     * @param content  记录列表
     * @param var2
     */
    public ApiResultPagingHelper(String varl, Long total, Long pageSize, Long page, List<T> content, D var2) {
        super(varl);
        this.total = total;
        this.pageSize = pageSize;
        this.page = page;
        this.content = content;
        this.data = var2;
    }

    public ApiResultPagingHelper(String varl, Long total, Integer pageSize, Integer page, List<T> content) {
        super(varl);
        if (null == total) {
            total = 0L;
        }
        if (pageSize == null) {
            pageSize = 0;
        }
        if (null == page) {
            page = 0;
        }
        this.total = total;
        this.pageSize = Long.valueOf(pageSize);
        this.page = Long.valueOf(page);
        this.content = content;
        this.data = null;
    }

    public ApiResultPagingHelper(String varl, Long total, Long pageSize, Long page, List<T> content) {
        super(varl);
        this.total = total;
        this.pageSize = pageSize;
        this.page = page;
        this.content = content;
        this.data = null;
    }

    Long getPageCount() {
        return (long) Math.ceil(this.total / this.pageSize);
    }

    public List<T> getContent() {
        return content;
    }

    public void setContent(List<T> content) {
        this.content = content;
    }

    public Long getTotal() {
        return total;
    }

    public void setTotal(Long total) {
        this.total = total;
    }

    public Long getPageSize() {
        return pageSize;
    }

    public void setPageSize(Long pageSize) {
        this.pageSize = pageSize;
    }

    public Long getPage() {
        return page;
    }

    public void setPage(Long page) {
        this.page = page;
    }

    public D getData() {
        return data;
    }

    public void setData(D data) {
        this.data = data;
    }
}
